<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2></h2>
    <script>
        let h2 = document.querySelector("h2")
        function timer() {
        let time = new Date()
        let year = time.getFullYear()
        let month = time.getMonth() < 10 ? "0" + (time.getMonth() + 1) : time.getMonth() + 1
        let day = time.getDate() < 10 ? "0" + (time.getDate()) : time.getDate()
        let hour = time.getHours() < 10 ? "0" + (time.getHours()) : time.getHours()
        let minute = time.getMinutes() < 10 ? "0" + (time.getMinutes()) : time.getMinutes()
        let second = time.getSeconds() < 10 ? "0" + (time.getSeconds()) : time.getSeconds()
        let da = time.getDay()
        let a = "";
        console.log(da);

        switch (da) {
            case 1:
                a = '星期一';
                break;
            case 2:
                a = '星期2';
                break;
            case 3:
                a = '星期三';
                break;
            case 4:
                a = '星期四';
                break;
            case 5:
                
                a = '星期五';
                break;
            case 6:
                a = '星期六';
                break;
            case 0:
                a = '星期日';
                break;
            default:
                alert(1111)
        }
        h2.innerHTML = `${a} +${year}-${month}-${day}  ${hour}:${minute}:${second}`

        // document.querySelector("body").innerHTML = ""   删除h2中的所有节点
        // document.querySelector("body").innerHTML = `<h2>${year}-${month}-${day}  ${hour}:${minute}:${second}</h2>`   
        console.log(a);
        }
        timer()
        // setInterval(timer, 1000)


    </script>
</body>

</html>